/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view.panels;

import java.awt.event.ActionEvent;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.table.TableModel;
import model.OpstiDomenskiObjekat;
import model.dataset.Dataset;
import view.forms.OpstaEkranskaForma;
import view.guicontrollers.ControllerUI_DataSet;
import view.guicontrollers.ControllerUI_Main;
import view.panels.tablemodels.TableModelDataSets;

/**
 *
 * @author Jelena
 */
public class PanelAllDataSets extends javax.swing.JPanel implements OpstaEkranskaForma{

    /**
     * Creates new form PanelAllDataSets
     */
    public PanelAllDataSets() {
        initComponents();
        tblDatasets.setComponentPopupMenu(postaviPopupmenu());     
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        tblDatasets = new javax.swing.JTable();

        tblDatasets.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jScrollPane1.setViewportView(tblDatasets);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 579, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 312, Short.MAX_VALUE)
                .addGap(39, 39, 39))
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tblDatasets;
    // End of variables declaration//GEN-END:variables

    /**
     * @return the tblDatasets
     */
    public javax.swing.JTable getTblDatasets() {
        return tblDatasets;
    }

    @Override
    public TableModel vratiModel() {
       return tblDatasets.getModel();
    }

    @Override
    public Object[] vratiPocetneVrednosti() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int vratiSelektovaniRed() {
        return tblDatasets.getSelectedRow();
    }

    @Override
    public OpstiDomenskiObjekat kreirajObjekat() {
        return odo;
    }

    OpstiDomenskiObjekat odo;

    public OpstiDomenskiObjekat getOdo() {
        return odo;
    }

    public void setOdo(OpstiDomenskiObjekat odo) {
        this.odo = odo;
    }

    
    private JPopupMenu postaviPopupmenu() {
        JPopupMenu jpm = new JPopupMenu("Dataset");
        JMenuItem jmiDetalji = new JMenuItem();
        jmiDetalji.setText("View details about dataset");
        jmiDetalji.addActionListener(new java.awt.event.ActionListener() {

            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiDetaljiActionPerformed(evt);
            }

            private void jmiDetaljiActionPerformed(ActionEvent evt) {
                try {
                    int red = tblDatasets.getSelectedRow();
                    Dataset ds =((TableModelDataSets)tblDatasets.getModel()).getDataSet(red);
                    FrmDataSet fds= new FrmDataSet(ControllerUI_Main.getInstance().getMainForm(), true);
                    ControllerUI_DataSet cads=new ControllerUI_DataSet(fds);
                    fds.setControllerDataSet(cads);
                    cads.setOdo(ds);
                    cads.setOef(fds);
                    cads.KonvertujDomenskiObjekatUGrafickiObjekat();
//                    fds.getBtnUpdate().setVisible(false);
                    fds.setVisible(true);
                } catch (IOException ex) {
                    Logger.getLogger(PanelAllDataSets.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
        jpm.add(jmiDetalji);
        
        
//        JMenuItem jmiIzmeni = new JMenuItem();
//        jmiIzmeni.setText("Edit dataset");
//        jmiIzmeni.addActionListener(new java.awt.event.ActionListener() {
//
//            public void actionPerformed(java.awt.event.ActionEvent evt) {
//                jmiIzmeniActionPerformed(evt);
//            }
//
//            private void jmiIzmeniActionPerformed(ActionEvent evt) {
//                try {
//                    int red = tblDatasets.getSelectedRow();
//                    Dataset ds =((TableModelDataSets)tblDatasets.getModel()).getDataSet(red);
//                    FrmDataSet fds= new FrmDataSet(ControllerUI_Main.getInstance().getMainForm(), true);
//                    ControllerUI_DataSet cads=new ControllerUI_DataSet(fds);
//                    fds.setControllerDataSet(cads);
//                    cads.setOdo(ds);
//                    cads.setOef(fds);
//                    cads.KonvertujDomenskiObjekatUGrafickiObjekat();
//                    fds.getBtnUpdate().setVisible(true);
//                    fds.setVisible(true);
//                } catch (IOException ex) {
//                    Logger.getLogger(PanelAllDataSets.class.getName()).log(Level.SEVERE, null, ex);
//                }
//            }
//        });
//        jpm.add(jmiIzmeni);
//        
        return jpm;
}
}
